﻿#pragma once

#define MLOBYTE(x) (*((uint8_t *)&(x)))  // low byte
#define MLOWORD(x) (*((uint16_t *)&(x))) // low word
#define LODWORD(x) (*((uint32_t *)&(x))) // low dword
#define MHIBYTE(x) (*((uint8_t *)&(x) + 1))
#define MHIWORD(x) (*((uint16_t *)&(x) + 1))
#define HIDWORD(x) (*((uint32_t *)&(x) + 1))

#define BYTEn(x, n) (*((uint8_t *)&(x) + n))
#define WORDn(x, n) (*((uint16_t *)&(x) + n))
#define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0)
#define BYTE2(x) BYTEn(x, 2)
#define BYTE3(x) BYTEn(x, 3)
#define BYTE4(x) BYTEn(x, 4)
#define BYTE5(x) BYTEn(x, 5)
#define BYTE6(x) BYTEn(x, 6)
#define BYTE7(x) BYTEn(x, 7)
#define BYTE8(x) BYTEn(x, 8)
#define BYTE9(x) BYTEn(x, 9)
#define BYTE10(x) BYTEn(x, 10)
#define BYTE11(x) BYTEn(x, 11)
#define BYTE12(x) BYTEn(x, 12)
#define BYTE13(x) BYTEn(x, 13)
#define BYTE14(x) BYTEn(x, 14)
#define BYTE15(x) BYTEn(x, 15)
#define WORD1(x) WORDn(x, 1)
#define WORD2(x) WORDn(x, 2) // third word of the object, unsigned
#define WORD3(x) WORDn(x, 3)
#define WORD4(x) WORDn(x, 4)
#define WORD5(x) WORDn(x, 5)
#define WORD6(x) WORDn(x, 6)
#define WORD7(x) WORDn(x, 7)
#define COERCE_UNSIGNED_INT64(x) *(uint64_t *)&(x)
#define COERCE_INT(x) *(int32_t *)&(x)
// now signed macros (the same but with sign extension)
#define SMLOBYTE(x) (*((int8_t *)&(x)))
#define SMLOWORD(x) (*((int16_t *)&(x)))
#define SLODWORD(x) (*((int32_t *)&(x)))
#define SMHIBYTE(x) (*((int8_t *)&(x) + 1))
#define SMHIWORD(x) (*((int16_t *)&(x) + 1))
#define SHIDWORD(x) (*((int32_t *)&(x) + 1))
#define SBYTEn(x, n) (*((int8_t *)&(x) + n))
#define SWORDn(x, n) (*((int16_t *)&(x) + n))
#define SBYTE1(x) SBYTEn(x, 1)
#define SBYTE2(x) SBYTEn(x, 2)
#define SBYTE3(x) SBYTEn(x, 3)
#define SBYTE4(x) SBYTEn(x, 4)
#define SBYTE5(x) SBYTEn(x, 5)
#define SBYTE6(x) SBYTEn(x, 6)
#define SBYTE7(x) SBYTEn(x, 7)
#define SBYTE8(x) SBYTEn(x, 8)
#define SBYTE9(x) SBYTEn(x, 9)
#define SBYTE10(x) SBYTEn(x, 10)
#define SBYTE11(x) SBYTEn(x, 11)
#define SBYTE12(x) SBYTEn(x, 12)
#define SBYTE13(x) SBYTEn(x, 13)
#define SBYTE14(x) SBYTEn(x, 14)
#define SBYTE15(x) SBYTEn(x, 15)
#define SWORD1(x) SWORDn(x, 1)
#define SWORD2(x) SWORDn(x, 2)
#define SWORD3(x) SWORDn(x, 3)
#define SWORD4(x) SWORDn(x, 4)
#define SWORD5(x) SWORDn(x, 5)
#define SWORD6(x) SWORDn(x, 6)
#define SWORD7(x) SWORDn(x, 7)
#define X7F 0x7F
#define X80 0x80
#define C32 ' '
#define C36 '$'
#define C66 'B'
#define C70 'F'
#define C78 'N'
#define C80 'P'
#define C83 'S'
#define C84 'T'
#define C86 'V'
#define C88 'X'
#define C115 's'
#define C116 't'
